<template>
  <div class="home-container">
    <!-- 欢迎横幅 -->
    <div class="welcome-banner">
      <div class="banner-content">
        <div class="banner-text">
          <h1 class="banner-title">
            <span class="title-emoji">🚀</span>
            欢迎来到现代化管理系统
          </h1>
          <p class="banner-subtitle" v-if="userStore.user">
            你好，<span class="username">{{ userStore.user.username }}</span>！
            今天是个美好的一天 ✨
          </p>
          <p class="banner-description">
            基于 Vue 3 + TypeScript + Element Plus 构建的企业级管理平台
          </p>
        </div>
        <div class="banner-decoration">
          <div class="floating-icon icon-1">💼</div>
          <div class="floating-icon icon-2">📊</div>
          <div class="floating-icon icon-3">⚡</div>
        </div>
      </div>
    </div>

    <!-- 统计卡片 -->
    <div class="stats-section">
      <h2 class="section-title">📈 系统概览</h2>
      <el-row :gutter="24" class="stats-row">
        <el-col :span="8" :xs="24" :sm="12" :md="8">
          <div class="stat-card gradient-blue">
            <div class="stat-icon">
              <el-icon size="40"><User /></el-icon>
            </div>
            <div class="stat-content">
              <div class="stat-number">{{ totalUsers }}</div>
              <div class="stat-label">总用户数</div>
              <div class="stat-trend">
                <el-icon color="#67c23a"><TrendCharts /></el-icon>
                <span>+12% 本月</span>
              </div>
            </div>
          </div>
        </el-col>

        <el-col :span="8" :xs="24" :sm="12" :md="8">
          <div class="stat-card gradient-green">
            <div class="stat-icon">
              <el-icon size="40"><Setting /></el-icon>
            </div>
            <div class="stat-content">
              <div class="stat-number">{{ totalRoles }}</div>
              <div class="stat-label">角色类型</div>
              <div class="stat-trend">
                <el-icon color="#67c23a"><TrendCharts /></el-icon>
                <span>稳定运行</span>
              </div>
            </div>
          </div>
        </el-col>

        <el-col :span="8" :xs="24" :sm="12" :md="8">
          <div class="stat-card gradient-orange">
            <div class="stat-icon">
              <el-icon size="40"><CircleCheck /></el-icon>
            </div>
            <div class="stat-content">
              <div class="stat-number">99.9%</div>
              <div class="stat-label">系统可用性</div>
              <div class="stat-trend">
                <el-icon color="#67c23a"><TrendCharts /></el-icon>
                <span>运行正常</span>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>


    <!-- 功能特性 -->
    <div class="features-section">
      <h2 class="section-title">🚀 核心功能</h2>
      <el-row :gutter="24" class="features-row">
        <el-col :span="12" :xs="24" :sm="12" :md="6">
          <div class="feature-card">
            <div class="feature-icon gradient-blue">
              <el-icon size="32"><User /></el-icon>
            </div>
            <div class="feature-content">
              <h4>用户管理</h4>
              <p>完整的用户增删改查功能，支持批量操作和权限控制</p>
            </div>
          </div>
        </el-col>

        <el-col :span="12" :xs="24" :sm="12" :md="6">
          <div class="feature-card">
            <div class="feature-icon gradient-green">
              <el-icon size="32"><Key /></el-icon>
            </div>
            <div class="feature-content">
              <h4>角色权限</h4>
              <p>灵活的角色权限管理系统，细粒度权限控制</p>
            </div>
          </div>
        </el-col>

        <el-col :span="12" :xs="24" :sm="12" :md="6">
          <div class="feature-card">
            <div class="feature-icon gradient-orange">
              <el-icon size="32"><Lock /></el-icon>
            </div>
            <div class="feature-content">
              <h4>安全认证</h4>
              <p>JWT Token 安全认证机制，保障系统安全</p>
            </div>
          </div>
        </el-col>

        <el-col :span="12" :xs="24" :sm="12" :md="6">
          <div class="feature-card">
            <div class="feature-icon gradient-purple">
              <el-icon size="32"><DataAnalysis /></el-icon>
            </div>
            <div class="feature-content">
              <h4>数据统计</h4>
              <p>实时的数据统计和分析，助力业务决策</p>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>

    <!-- 快速操作 -->
    <div class="quick-actions-section">
      <h2 class="section-title">⚡ 快速操作</h2>
      <div class="quick-actions">
        <el-button type="primary" size="large" class="action-btn">
          <el-icon><Plus /></el-icon>
          添加用户
        </el-button>
        <el-button type="success" size="large" class="action-btn">
          <el-icon><Setting /></el-icon>
          系统设置
        </el-button>
        <el-button type="warning" size="large" class="action-btn">
          <el-icon><DataAnalysis /></el-icon>
          查看报表
        </el-button>
        <el-button type="info" size="large" class="action-btn">
          <el-icon><Document /></el-icon>
          系统日志
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useUserStore } from '@/stores/counter'
import { getRoleStats } from '@/api/roles'
import { User, Setting, CircleCheck, Key, Lock, DataAnalysis, TrendCharts, Plus, Document } from '@element-plus/icons-vue'

const userStore = useUserStore()
const totalUsers = ref(0)
const totalRoles = ref(0)

onMounted(async () => {
  try {
    const response = await getRoleStats()
    if (response.success) {
      totalUsers.value = response.data.totalUsers
      totalRoles.value = response.data.statistics.length
    }
  } catch (error) {
    console.error('获取统计数据失败:', error)
  }
})
</script>

<style scoped>
.home-container {
  min-height: 100%;
  background: transparent;
}

/* 欢迎横幅 */
.welcome-banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20px;
  padding: 40px;
  margin-bottom: 32px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
}

.banner-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 2;
}

.banner-text {
  flex: 1;
  color: white;
}

.banner-title {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 0 0 16px 0;
  display: flex;
  align-items: center;
  gap: 16px;
}

.title-emoji {
  font-size: 3rem;
  animation: bounce 2s infinite;
}

.banner-subtitle {
  font-size: 1.2rem;
  margin: 0 0 12px 0;
  opacity: 0.95;
}

.username {
  font-weight: 600;
  color: #ffd700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.banner-description {
  font-size: 1rem;
  margin: 0;
  opacity: 0.85;
}

.banner-decoration {
  position: relative;
  width: 200px;
  height: 150px;
}

.floating-icon {
  position: absolute;
  font-size: 2rem;
  animation: float 3s ease-in-out infinite;
}

.icon-1 {
  top: 20px;
  left: 20px;
  animation-delay: 0s;
}

.icon-2 {
  top: 60px;
  right: 30px;
  animation-delay: 1s;
}

.icon-3 {
  bottom: 20px;
  left: 50px;
  animation-delay: 2s;
}

/* 章节标题 */
.section-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 24px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 统计卡片 */
.stats-section {
  margin-bottom: 32px;
}

.stats-row {
  margin-bottom: 0;
}

.stat-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  margin-bottom: 16px;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--gradient);
}

.stat-card.gradient-blue {
  --gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-card.gradient-green {
  --gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.stat-card.gradient-orange {
  --gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient);
  color: white;
  margin-bottom: 16px;
}

.stat-content {
  text-align: left;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: #2c3e50;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin-bottom: 8px;
}

.stat-trend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: #67c23a;
  font-weight: 500;
}

/* 功能特性 */
.features-section {
  margin-bottom: 32px;
}

.features-row {
  margin-bottom: 0;
}

.feature-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  text-align: center;
  margin-bottom: 16px;
  height: 100%;
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.feature-icon {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient);
  color: white;
  margin: 0 auto 16px;
}

.feature-card .gradient-purple {
  --gradient: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

.feature-content h4 {
  font-size: 1.1rem;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 8px 0;
}

.feature-content p {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin: 0;
  line-height: 1.5;
}

/* 快速操作 */
.quick-actions-section {
  margin-bottom: 32px;
}

.quick-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.action-btn {
  border-radius: 12px;
  padding: 12px 24px;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

/* 动画 */
@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .banner-content {
    flex-direction: column;
    text-align: center;
  }

  .banner-decoration {
    display: none;
  }

  .banner-title {
    font-size: 2rem;
  }

  .quick-actions {
    flex-direction: column;
    align-items: center;
  }

  .action-btn {
    width: 200px;
  }
}
</style>
